home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / terminal / qterm-6.0 / qterm-6 / signals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-04  |  1.8 KB  |  91 lines

  1. #ifndef lint
  2. static char RCSid[] = 
  3. "$Id: signals.c,v 6.2 1993/05/04 18:21:37 mcooper Exp mcooper $";
  4.  
  5. static char copyright[] =
  6. "@(#) Copyright (c) 1990-1993 Michael A. Cooper.\n\
  7.  All rights reserved.\n";
  8. #endif
  9.  
  10. /*
  11.  * Copyright (c) 1990-1993 Michael A. Cooper.
  12.  * This software may be freely distributed provided it is not sold for 
  13.  * profit and the author is credited appropriately.
  14.  */
  15.  
  16. #include "config.h"
  17. #include "qterm.h"
  18. #include <stdio.h>
  19. #include <signal.h>
  20.  
  21. #if    SIG_TYPE == SIGTYPE_POSIX
  22. void SetupSignals(func)
  23.     void               (*func)();
  24. {
  25.     struct sigaction        act;
  26.  
  27.     sigemptyset(&act.sa_mask);
  28.     act.sa_flags = 0;
  29.     act.sa_handler = func;
  30.  
  31.     (void) sigaction(SIGINT, &act, (struct sigaction *)NULL);
  32.     (void) sigaction(SIGHUP, &act, (struct sigaction *)NULL);
  33.     (void) sigaction(SIGTERM, &act, (struct sigaction *)NULL);
  34. }
  35. #endif    /* SIGTYPE_POSIX */
  36.  
  37. #if    SIG_TYPE == SIGTYPE_UNIX
  38. void SetupSignals(func)
  39.     void               (*func)();
  40. {
  41.     (void) signal(SIGINT, func);
  42.     (void) signal(SIGHUP, func);
  43.     (void) signal(SIGTERM, func);
  44. }
  45. #endif    /* SIGTYPE_UNIX */
  46.  
  47. /*
  48.  * Turn off alarm
  49.  */
  50. void AlarmOff()
  51. {
  52.     (void) alarm((unsigned) 0);
  53. }
  54.  
  55. #if    SIG_TYPE == SIGTYPE_POSIX
  56. /*
  57.  * POSIX turn on alarm
  58.  */
  59. void AlarmOn(timeout, func)
  60.     int                timeout;
  61.     void               (*func)();
  62. {
  63.     struct sigaction        act;
  64.  
  65.     AlarmOff();
  66.  
  67.     sigemptyset(&act.sa_mask);
  68.     act.sa_flags = 0;
  69.     act.sa_handler = func;
  70.     if (sigaction(SIGALRM, &act, (struct sigaction *)NULL) != 0)
  71.     Error("sigaction failed to set SIGALRM: %s.", SYSERR);
  72.  
  73.     (void) alarm(timeout);
  74. }
  75. #endif    /* SIGTYPE_POSIX */
  76.  
  77. #if    SIG_TYPE == SIGTYPE_UNIX
  78. /*
  79.  * Unix turn on alarm
  80.  */
  81. void AlarmOn(timeout, func)
  82.     int                timeout;
  83.     void              (*func)();
  84. {
  85.     AlarmOff();
  86.  
  87.     (void) signal(SIGALRM, func);
  88.     (void) alarm(timeout);
  89. }
  90. #endif    /* SIGTYPE_UNIX */
  91.